package br.com.registrofinancas.util;

import br.com.registrofinancas.R;
import android.annotation.SuppressLint ;
import android.app.Notification ;
import android.app.NotificationManager ;
import android.app.PendingIntent ;
import android.content.Context ;
import android.content.Intent ;
import android.os.Vibrator;

public class NotificationUtil{
	private static int ID = 0 ;

	@SuppressLint( "NewApi" )
	public static void generateNotification( Context context, String message,
			Intent notificationIntent )
	{
		NotificationManager notificationManager = ( NotificationManager ) context
				.getSystemService( Context.NOTIFICATION_SERVICE ) ;

		notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
		
		PendingIntent intent = PendingIntent.getActivity( context, ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT ) ;		
		
		String title = context.getString( R.string.app_name ) ;
		Notification.Builder builder = new Notification.Builder( context )
				.setContentTitle( message ).setContentText( title ).setContentIntent( intent )
				.setSmallIcon( R.drawable.ic_launcher ) ;

		Notification notification = builder.build( ) ;

		notification.flags |= Notification.FLAG_AUTO_CANCEL ;
		notificationManager.notify( ID++, notification ) ;
		
		vibrate(context);
		
	}
	
	public static void vibrate(Context contexto){
		Vibrator v = (Vibrator) contexto.getSystemService(Context.VIBRATOR_SERVICE);
		v.vibrate(3000);
	}
		
}

